package com.share.lottery.activity.kaijanggonggao;

import java.util.List;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.share.lottery.R;
import com.share.lottery.adapter.KjggAdapter;
import com.share.lottery.base.BaseActivity;
import com.share.lottery.base.Constants;
import com.share.lottery.model.BulletinBean;

public class KjggActivity extends BaseActivity {
	private PullToRefreshListView pullToRefreshListView = null;
	private KjggAdapter adapter;

	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.kjgg_main);
		init();				
	}

	public void findView() {
		pullToRefreshListView = (PullToRefreshListView)findViewById(R.id.audio_list);
		pullToRefreshListView.setMode(Mode.BOTH);
		pullToRefreshListView.setOnRefreshListener(new MyOnRefreshListener2(
				pullToRefreshListView));

	}


	public void getData() {
	//	BulletInController.getInstance().bulletinList(handler, "0");
	}


	private TextView titleTv;
	public void initTitle() {
		ImageButton titleLeftImg = (ImageButton) findViewById(R.id.title_left_img);
		ImageButton titleRightImg = (ImageButton) findViewById(R.id.title_right_img);
		titleTv = (TextView) findViewById(R.id.title_tv_center);

		titleLeftImg.setImageResource(R.drawable.back);
		titleTv.setText("开奖公告");
		titleRightImg.setVisibility(View.VISIBLE);
		titleLeftImg.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				finish();

			}
		});
	}


	public void setData() {
		if (adapter == null) {
			adapter = new KjggAdapter(this);
		}
		pullToRefreshListView.setAdapter(adapter);


	}

	@Override
	public void setonCliker() {


	}

	/**
	 * 
	 * @ClassName:MyOnRefreshListener2
	 * @Description:TODO 下拉刷新类
	 * @author py
	 * 
	 */
	class MyOnRefreshListener2 implements OnRefreshListener2<ListView> {

		private PullToRefreshListView mPtflv;

		public MyOnRefreshListener2(PullToRefreshListView ptflv) {
			this.mPtflv = ptflv;

		}

		@Override
		public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
			// 下拉刷新
			String mLabel = DateUtils.formatDateTime(
					KjggActivity.this,
					System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME
					| DateUtils.FORMAT_SHOW_DATE
					| DateUtils.FORMAT_ABBREV_ALL);

			refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(mLabel);


		}



		@Override
		public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
			// 上拉加载

		}

	}

	private void doMessage(Message msg) {
		switch (msg.arg1) {
		case Constants.HTTP_OK://请求成功
			List<BulletinBean> caiboRecommondBeanList = (List<BulletinBean>) msg.obj;
			if (caiboRecommondBeanList != null) {
				adapter.addDatas(caiboRecommondBeanList);
			}

			break;
		case Constants.HTTP_ERROR://请求错误
			String serror = (String) msg.obj;
			showShortToast(serror);
			break;
		case Constants.HTTP_ERROR_PASER://数据解析错误
			showShortToast("数据解析错误");
			break;
		case Constants.HTTP_ERROR_NET://网络错误

			showShortToast("网络错误，请检查网络");
			break;

		default:
			break;
		}

	}

	Handler handler = new Handler(){
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case Constants.BULLETIN_LIST:
				doMessage(msg);
				break;

			default:
				break;
			}

		}


	};


}
